package com.fsh.anime.controller;

import com.fsh.anime.model.dtos.EmpLoginDto;
import com.fsh.anime.model.vos.Result;
import com.fsh.anime.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/api/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    /**
     * 登录
     *
     * @param dto dto
     * @return {@link Result}
     */
    @PostMapping("/login")
    public Result login(@RequestBody EmpLoginDto dto, BindingResult results){
        if (results.hasErrors()){
            return Result.error(results.getFieldError().getDefaultMessage());
        }
        log.info("EmpLoginDto，{}",dto);
        return employeeService.login(dto);
    }

}
